/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package acousticfield3d.gui.panels;

import acousticfield3d.gui.MainForm;
import acousticfield3d.math.Vector3f;
import acousticfield3d.scene.Entity;
import acousticfield3d.scene.Scene;
import acousticfield3d.simulation.Simulation;
import acousticfield3d.utils.Parse;

/**
 *
 * @author Asier
 */
public class DomainPanel extends javax.swing.JPanel {
    public MainForm mf;
    
    public DomainPanel(MainForm mf) {
        this.mf = mf;
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel18 = new javax.swing.JLabel();
        adjustButton = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        guiGainText = new javax.swing.JTextField();
        showSimBBCheck = new javax.swing.JCheckBox();
        showCubeCheck = new javax.swing.JCheckBox();
        simEqCubeButton = new javax.swing.JButton();
        cubeEqSimButton = new javax.swing.JButton();

        jLabel18.setText("Domain size:");

        adjustButton.setText("Adjust");
        adjustButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                adjustButtonActionPerformed(evt);
            }
        });

        jLabel14.setText("GUI gain");

        guiGainText.setText("0.01");

        showSimBBCheck.setSelected(true);
        showSimBBCheck.setText("ShowBB");
        showSimBBCheck.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showSimBBCheckActionPerformed(evt);
            }
        });

        showCubeCheck.setText("show cube");
        showCubeCheck.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showCubeCheckActionPerformed(evt);
            }
        });

        simEqCubeButton.setText("sim = cube");
        simEqCubeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                simEqCubeButtonActionPerformed(evt);
            }
        });

        cubeEqSimButton.setText("cube = sim");
        cubeEqSimButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cubeEqSimButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(simEqCubeButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(adjustButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(showCubeCheck, javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel14)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(guiGainText))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel18)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(showSimBBCheck)))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(cubeEqSimButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(showSimBBCheck))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(guiGainText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(adjustButton)
                .addGap(18, 18, 18)
                .addComponent(showCubeCheck)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(simEqCubeButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cubeEqSimButton)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void adjustButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_adjustButtonActionPerformed
        mf.simulation.updateSimulationBoundaries();
        
        mf.scene.updateBoundaryBoxes( mf.simulation );
        mf.scene.adjustCameraNearAndFar( mf.simulation );
        
        mf.needUpdate();
    }//GEN-LAST:event_adjustButtonActionPerformed

    private void showSimBBCheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showSimBBCheckActionPerformed
        Scene.setVisible(mf.scene.getEntities(), Entity.TAG_SIMULATION_BOUNDINGS, showSimBBCheck.isSelected());
        mf.needUpdate();
    }//GEN-LAST:event_showSimBBCheckActionPerformed

    private void showCubeCheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showCubeCheckActionPerformed
        Scene.setVisible(mf.scene.getEntities(), Entity.TAG_CUBE_HELPER, showCubeCheck.isSelected());
        mf.needUpdate();
    }//GEN-LAST:event_showCubeCheckActionPerformed

    private void simEqCubeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_simEqCubeButtonActionPerformed
        mf.simulation.copyFromCube( mf.scene.getCubeHelper() );
        mf.scene.updateBoundaryBoxes( mf.simulation );
        mf.needUpdate();
    }//GEN-LAST:event_simEqCubeButtonActionPerformed

    private void cubeEqSimButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cubeEqSimButtonActionPerformed
        mf.simulation.copyToCube( mf.scene.getCubeHelper() );
        mf.needUpdate();
    }//GEN-LAST:event_cubeEqSimButtonActionPerformed

    public float getGUIGain(){
        return Parse.toFloat( guiGainText.getText() );
    }
    
    public void setGUIGain(float gain){
        guiGainText.setText( gain + "");
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton adjustButton;
    private javax.swing.JButton cubeEqSimButton;
    private javax.swing.JTextField guiGainText;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JCheckBox showCubeCheck;
    private javax.swing.JCheckBox showSimBBCheck;
    private javax.swing.JButton simEqCubeButton;
    // End of variables declaration//GEN-END:variables
}
